package no.uio.ifi.cop.cl;

import java.util.Set;
import no.uio.ifi.cop.parse.formula.TermFactory;

/**
 * Holds constants inside Terms (Predicates).
 *
 * All constants such that const1.equals(const2) also
 * have this property: const1.getId() == const2.getId().
 *
 * I.e. we compare constants by comparing String pointers,
 * this is ensured by our {@link no.uio.ifi.cop.parse.formula.TermFactory}.
 *
 * @version 1.0
 * @author bjarneh@ifi.uio.no
 */

public final class Constant implements Term, Cloneable{

    private String id;

    public Constant(String id){
        this.id = id;
    }

    public String getId()  { return id;  }
    public String strType(){ return "Constant"; }
    
    public boolean isVariable() { return false; }
    public boolean isPredicate(){ return false; }
    public boolean isConstant() { return true;  }
    public String toString(){ return id;  }
    public int hashCode()   { return id.hashCode(); }
    public Term apply(Substitution subst){ return this; }
    public void gatherVariables(Set<String> set){}

    public boolean equals(Object other){
        if( other instanceof Constant ){
            Constant c_other = (Constant) other;
            return c_other == this;
        }
        return false;
    }

    public Constant clone(){
        return TermFactory.getConstant( id );
    }

    public boolean match(Substitution subst, Term other){
        if(other.isConstant() && other == this){
            return true;
        }
        return false;
    }

    public Substitution smatch(Term other){
        return null;
    }

}
